package gold.contest;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC5236 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minDeletion(int[] nums) {
            int cnt = 0, i = 0, j = 1;
            while (i < nums.length) {
                if (j >= nums.length) {
                    cnt++;
                    break;
                }

                while (j < nums.length && nums[j] == nums[i]) {
                    j++;
                    cnt++;
                }
                i = j + 1;
                j = j + 2;
            }

            if ((nums.length - cnt) % 2 != 0) cnt++;
            return cnt;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.minDeletion(InputUtil.toIntegerArray("[1,1,2,3,5]")));
        System.out.println(solution.minDeletion(InputUtil.toIntegerArray("[1,1,2,2,3,3]")));
        System.out.println(solution.minDeletion(InputUtil.toIntegerArray("[2,6,2,5,8,9,7,2,2,5,6,2,2,0,6,8,7,3,9,2,1,1,3,2,6,2,4,6,5,8,4,8,7,0,4,8,7,8,4,1,1,4,0,1,5,7,7,5,9,7,5,5,8,6,4,3,6,5,1,6,7,6,9,9,6,8,6,0,9,5,6,7,6,9,5,5,7,3,0,0,5,5,4,8,3,9,3,4,1,7,9,3,1,8,8,9,1,6,0,0]")));
    }

    public static void main(String[] args) throws Exception {
        LC5236 an = new LC5236();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
